<%@ page import="edu.zut.pojo.SysUser" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--获取request/session/servletContext/cookie中的数据--%>
<p>名字：<%=request.getAttribute("myName")%></p>
<%--使用el简化取值操作  ${表达式}   ${作用域对象.key}--%>
<p>名字：${requestScope.myName}</p>
<%--使用el从作用域对象中取值时，如果key是唯一的，可以省略作用域对象
    直接根据key从作用域对象中取值，默认按照page----> request--->session---->application的顺序自动取值
    找到就立刻返回，找不到就返回“”
--%>
<p>名字：${myName}</p>
<p>年龄：<%=session.getAttribute("myAge")%></p>
<p>年龄：${sessionScope.myAge}</p>
<p>年龄：${myAge}</p>

<p>school:<%=application.getAttribute("school")%></p>
<p>school:${applicationScope.school}</p>
<p>school:${school}</p>

<%
    Cookie[] cookies = request.getCookies();
    String value = "";
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals("myPhone")){
            value = cookie.getValue();
        }
    }
%>
<p>phone: <%=value%></p>
<%--${cookie.key}--%>
<p>phone: ${cookie.myPhone.value}</p>

<%--如果数据是对象或者数组、集合、map--%>
<%
    SysUser sysUser = new SysUser("jack", 21);
    SysUser sysUser2 = new SysUser("tom", 22);
    request.setAttribute("sysUser",sysUser);
    List<SysUser> list = new ArrayList<>();
    list.add(sysUser);
    list.add(sysUser2);
    request.setAttribute("list",list);
    Map<String,SysUser> userMap = new HashMap<>();
    userMap.put(sysUser.getName(),sysUser);
    userMap.put(sysUser2.getName(),sysUser2);
    request.setAttribute("userMap",userMap);
    request.setAttribute("num1",100);
    request.setAttribute("num2",200);
    request.setAttribute("num3","");

%>

<%--数据是对象--%>
<p>${sysUser.name}</p>
<p>${sysUser.age}</p>
<%--使用下标操作集合、数组--%>
<p>${list[0].name}</p>
<p>${list[0].age}</p>
<p>${list[1].name}</p>
<p>${list[1].age}</p>
<p>---------------------------------</p>
<p>${userMap.jack.name}</p>
<p>${userMap.jack.age}</p>
<p>-------------------------</p>
num1 + num2 = ${num2 + num1}
${num2 == num1}
<%--判断是否为空--%>
${empty num3}
${num3 == null || num3 == ""}
<%--显示用户头像
    jstl：标签库   简化jsp中的流程控制
    使用：1、导包  jstl-1.2   2、引用
--%>

</body>
</html>
